# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import *
import d_task
import d_share
import d_server
import time

class Share:
    def __init__(self):
        pass

    # 完成一次分享转发后调用
    def shareComplete(self):
        self.task_daily_update(d_task.task["mode_share"]["value"])

    # 点击一个分享链接后调用
    def shareClick(self, dbid, shareType):
        self.client.onShareClick(dbid, shareType)
        dbid = int(dbid, 16)
        shareType = int(shareType)
        self.share_click(dbid, {"shareType" : shareType})

    def share_click(self, dbid, params):
        # params参数为字典类型,必须包含shareType的数值参数
        print("share_click ==>> dbid : ", dbid, ", params : ", params)
        if self.dbid == dbid:
            return
        if dbid in self.share_clicks:
            return
        # 在链接玩家的实体中处理
        params["nickName"] = self.nickName
        params["avatarUrl"] = self.avatarUrl
        self.getOtherAccount(dbid, d_server.GetAccountType.ClickLink, params)

    # 被邀请的新玩家
    def share_invite(self, dbid, params):
        print("share_invite ==>> dbid : ", dbid, ", params : ", params)
        if self.dbid == dbid:
            return
        self.share_invite = dbid
        self.share_click(dbid, params)

    # 一个分享链接被点击后调用
    def share_link(self, accountRef, dbid, params):
        print("share_link ==>> accountRef : ",accountRef, ", dbid : ", dbid, ", params : ", params)
        if dbid in self.share_links:
            return
        if "isNewChar" in params and True == params["isNewChar"]:
            self.share_subset.append(dbid)
            if "shareType" in params and params["shareType"] == d_share.share["share_type_shield"]["value"]:
                self.addShieldInvite(dbid, params["nickName"], params["avatarUrl"])
                self.mailOptOTM(d_share.share["share_type_shield"]["value"], params["nickName"], 0, 0, int(time.time()))

        self.friend_binding(dbid)
        self.share_links.append(dbid)
        accountRef.share_click_call(dbid, params)

    def share_click_call(self, dbid, params):
        print("share_click_call ==>> dbid : ", dbid, ", params : ", params)
        # 自己的点击过的链接数据中添加记录
        self.share_clicks.append(dbid)

